package com.yloveg.common;

import java.util.LinkedHashMap;
import java.util.Map;

public class FreemarkUtil {
	
		/**
		 * 1 是否
		 * @author Administrator
		 *
		 */
		public enum YesOrNo {
			YES("是","1"),
			NO("否","2");
			private String name;  
		    private String value;  
		    // 构造方法  
		    private YesOrNo(String name, String value) { 
		    	this.name = name;
		        this.value = value;  
		          
		    }
			public String getname() {
				return name;
			}
			public void setname(String name) {
				this.name = name;
			}
			public String getValue() {
				return value;
			}
			public void setValue(String value) {
				this.value = value;
			}
		}
		//后台调用
	    public static String YesOrNoNmame(String value) {  
	        for (YesOrNo b : YesOrNo.values()) {  
	            if (b.getValue().equals(value) ) {  
	                return b.name;
	            }  
	        }  
	      return null;  
	    } 
		/**
		 * 2状态
		 * @author Administrator
		 *
		 */
		public enum State {
			IN_AUDIT("审核中","2"),
			PASS("通过","1"),
			NO_PASS("未通过","0");
			private String name;  
		    private String value;  
		    // 构造方法  
		    private State(String name, String value) { 
		    	this.name = name;
		        this.value = value;  
		          
		    }
			public String getname() {
				return name;
			}
			public void setname(String name) {
				this.name = name;
			}
			public String getValue() {
				return value;
			}
			public void setValue(String value) {
				this.value = value;
			}
		}
		//后台调用
	    public static String getStateName(String value) {  
	        for (State b : State.values()) {  
	            if (b.getValue().equals(value) ) {  
	                return b.name;
	            }  
	        }  
	      return null;  
	    } 
	
		/**
		 * 3商品类别
		 * @author Administrator
		 *
		 */
			public enum ProductType {
				FRUITS("干鲜果","1"),
				GREENS("干鲜菜","2"),
				CRUDE_DRUGS("药材","3"),
				AQUATIC_PRODUCT("水产品","4"),
				PRODUCT_OTHER("其他","20");
				private String name;  
			    private String value;  
			    // 构造方法  
			    private ProductType(String name, String value) { 
			    	this.name = name;
			        this.value = value;  
			          
			    }
				public String getname() {
					return name;
				}
				public void setname(String name) {
					this.name = name;
				}
				public String getValue() {
					return value;
				}
				public void setValue(String value) {
					this.value = value;
				}
			}
			//后台调用
		    public static String ProductTypeNmame(String value) {  
		        for (ProductType b : ProductType.values()) {  
		            if (b.getValue().equals(value) ) {  
		                return b.name;
		            }  
		        }  
		      return null;  
		    }
		    
		    /**
			 *4支付类型
			 * @author Administrator
			 *
			 */
				public enum PaymentType {
					ZFBH5("支付宝H5","1"),
					ZFBAPP("支付宝APP","2"),
					WXH5("微信H5","3"),
					WXAPP("微信APP","4");
					
					private String name;  
				    private String value;  
				    // 构造方法  
				    private PaymentType(String name, String value) { 
				    	this.name = name;
				        this.value = value;  
				          
				    }
					public String getname() {
						return name;
					}
					public void setname(String name) {
						this.name = name;
					}
					public String getValue() {
						return value;
					}
					public void setValue(String value) {
						this.value = value;
					}
				}
				//后台调用
			    public static String PaymentTypeNmame(String value) {  
			        for (PaymentType b : PaymentType.values()) {  
			            if (b.getValue().equals(value) ) {  
			                return b.name;
			            }  
			        }  
			      return null;  
			    }  
	    /*************************************下拉表*************************************************/
	    
	    /**
	     * 枚举数据获取
	     */
	    private static Map<Object, Object> getSelectData(String type){
	    	Map<Object, Object> dataMap = new LinkedHashMap<Object, Object>();
	    	//是否
	    	if(type.equals("yesOrNo")){
	    		YesOrNo[] yesOrNo = YesOrNo.values();
	    		for (YesOrNo temp : yesOrNo) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//通过状态
	    	if(type.equals("state")){
	    		State[] state = State.values();
	    		for (State temp : state) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}	
	    	//商品类型
	    	if(type.equals("productType")){
	    		ProductType[] productType = ProductType.values();
	    		for (ProductType temp : productType) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}
	    	//支付类型
	    	if(type.equals("paymentType")){
	    		PaymentType[] paymentType = PaymentType.values();
	    		for (PaymentType temp : paymentType) {
	    			dataMap.put(temp.name, temp.value);
				}
	    	}	    	
	    	return dataMap;
	    }
		/**
		 * 获取枚举类型下拉表
		 * @param type：字典类型
		 * @param value：值
		 * @return
		 */
		public static  String getOption(String type,String value){
			Map<Object, Object> dataMap = getSelectData(type);
			return option(dataMap,value);
		}
		public static String option(Map<Object, Object> dataMap,String isvalue){
			StringBuilder sb = new StringBuilder();
			if(dataMap.size() > 0 && dataMap != null){
				sb.append("<option value='' >---请选择---</option>");
				for (Object temp : dataMap.keySet()) {
					String value = dataMap.get(temp).toString();
					String name = temp.toString();
					sb.append("<option value='").append(value).append("'");
					if(value.equals(isvalue)){
						sb.append(" selected='selected'");
					}
					sb.append(">").append(name).append("</option>");
				}
			}
			
			return sb.toString();		
		}
		
}
